package comWorld.home.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gjs.tools.utils.Utils;

import comWorld.blog.BlogInfo;
import comWorld.blog.BlogInfoManage;
import comWorld.blog.BlogInfos;
import comWorld.blog.BlogLog;

/**
 * Servlet implementation class HomePageInit
 */
@WebServlet("/homePageInit")
public class HomePageInit extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HomePageInit() {
        super();
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		List<BlogInfo> hotBlogs = BlogInfoManage.getHotBlogs(0).getBlogs();
		request.setAttribute("hotBlogs", hotBlogs);
		
		List<BlogLog> recentBlogs = BlogInfoManage.getBlogLogs(0, "home", 1);
		int[] be = Utils.paging(request, 15, recentBlogs.size());
		request.setAttribute("recentBlogs", recentBlogs.subList(be[0], be[1]));
		request.getRequestDispatcher("/homePage.jsp").forward(request, response);
	}

}
